#pragma once
//------------------------------------------------------------------------------
/**
    @class Characters::CharacterNode
  
    The CharacterNode class wraps a Character object into a ModelNode
    for rendering.
    
    (C) 2008 Radon Labs GmbH
*/  
#include "transformnode.h"
#include "characterjoint.h"
#include "COLLADAFWUniqueId.h"

//------------------------------------------------------------------------------
namespace Characters
{
class CharacterNode : public Models::TransformNode
{
    __DeclareClass(CharacterNode);
public:
    /// constructor
    CharacterNode();
    /// destructor
    virtual ~CharacterNode();

	// write data to stream
	virtual bool WriteDataTag(Ptr<ToolkitUtil::ModelWriter>& writer);
    /// set the character's animation resource
    void SetAnimationResourceId(const Util::String& resId);
	/// add SkinList 
	void AddSkin(const Util::String& skinNodename);
	/// add joint
	void AddJoint(const COLLADAFW::UniqueId uniqueId,const CharacterJoint& joint);
	/// get joint
	CharacterJoint& GetJoint(const COLLADAFW::UniqueId& uniqueId);
	/// has joint by uniqueID
	bool HasJoint(const COLLADAFW::UniqueId& uniqueId);
	/// Set tje character's animation variation res
	void SetVariationResourceId(const Util::String& resId);
	/// get joint num
	SizeT NumJoint() const;
	/// get joint indices
	Util::Array<IndexT> GetJointIndices();

private:
	Util::String animResId;
	Util::String variationsResId;
	Util::Array<Util::String> skinList;
	Util::Dictionary<COLLADAFW::UniqueId,Characters::CharacterJoint> jointMaps;
};

//------------------------------------------------------------------------------
/**
*/
inline void
CharacterNode::SetAnimationResourceId(const Util::String& resId)
{
    this->animResId = resId;
}

//------------------------------------------------------------------------------
/**
*/
inline void
CharacterNode::SetVariationResourceId(const Util::String& resId)
{
    this->variationsResId = resId;
}

//------------------------------------------------------------------------------
/**
*/
inline void
CharacterNode::AddSkin(const Util::String& skinNodename)
{
	this->skinList.Append(skinNodename);
}

//------------------------------------------------------------------------------
/**
*/
inline void
CharacterNode::AddJoint(const COLLADAFW::UniqueId uniqueId,const CharacterJoint& joint)
{
	this->jointMaps.Add(uniqueId,joint);
}

//------------------------------------------------------------------------------
/**
*/
inline CharacterJoint& 
CharacterNode::GetJoint(const COLLADAFW::UniqueId& uniqueId)
{	
	return this->jointMaps[uniqueId];
}

//------------------------------------------------------------------------------
/**
*/
inline bool
CharacterNode::HasJoint(const COLLADAFW::UniqueId& uniqueId)
{	
	return this->jointMaps.Contains(uniqueId);
}

//------------------------------------------------------------------------------
/**
*/
inline SizeT 
CharacterNode::NumJoint() const
{
	return this->jointMaps.Size();
}

//------------------------------------------------------------------------------
/**
*/
inline
Util::Array<IndexT> 
CharacterNode::GetJointIndices()
{
	Util::Array<IndexT> jointIndices;
	Util::Array<Characters::CharacterJoint> joints = this->jointMaps.ValuesAsArray();
	for (IndexT index=0; index< joints.Size();index++)
	{
		jointIndices.Append(joints[index].GetJointIndex());
	}
	return jointIndices;
}

} // namespace Characters
//------------------------------------------------------------------------------
  